package com.tcu.user.controller.spec;

import com.tcu.exception.SmartException;
import com.tcu.result.R;
import com.tcu.user.entity.spec.AppUser;
import com.tcu.user.entity.spec.WebUser;
import com.tcu.user.service.spec.IWebUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/web-user")
public class WebUserController {
    private IWebUserService webUserService;

    @PostMapping("add")
    public R addInfo(@RequestBody WebUser webUser){
        if (webUser.getUid()==null) {
            throw new SmartException(20001,"用户id不能为空");
        }
        webUserService.save(webUser);
        return R.success();
    }
    @DeleteMapping("delete/{id}")
    public R delete(@PathVariable String id){
        boolean b = webUserService.removeById(id);
        return b ? R.success() : R.error();
    }
    @PostMapping("update")
    public R update(@RequestBody WebUser webUser){
        if (webUser.getUid()==null) {
            throw new SmartException(20001,"用户id不能为空");
        }
        boolean b = webUserService.updateById(webUser);
        return b ? R.success() : R.error();
    }
    @GetMapping("getInfo/{id}")
    public R getInfo(@PathVariable String id){
        WebUser byId = webUserService.getById(id);
        return R.success().data("webUserInfo", byId);
    }


    @Autowired
    public void setWebUserService(IWebUserService webUserService) {
        this.webUserService = webUserService;
    }
}
